<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用代理拦截动态属性</title>
</head>
<body>
    
</body>
<script>
// 创建一个 Proxy，拦截属性访问
function createProxy(values =[]) { 
  return new Proxy({}, {
    get(target,  p) {
        if(p===Symbol.toPrimitive){
            return ()=>values.reduce((a,b)=>a+b,0)
        }
      return createProxy([...values,+p]);
    }
  });
}

const add = createProxy();
const result=add[1][2][3]+4;
console.log(result)
</script>
</html>